package com.ruoyi.project.wxapi.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.meal.domain.MealServiceObjects;
import com.ruoyi.project.meal.domain.MealServiceObjectsList;
import com.ruoyi.project.meal.domain.MealWorker;
import com.ruoyi.project.meal.service.IMealServiceObjectsListService;
import com.ruoyi.project.meal.service.IMealServiceObjectsService;
import com.ruoyi.project.meal.service.IMealWorkerService;
import com.ruoyi.project.wxapi.model.dto.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("职工报餐")
@RestController
@RequestMapping("/wxapi/worker")
public class WxapiWorkerController {

    @Autowired
    IMealWorkerService workerService;

    @RequestMapping("/lists")
    public Result lists(String reportName,String reportDate,String phone) {
        MealWorker mealWorker=new MealWorker();
        if(StringUtils.isEmpty(reportName)||StringUtils.isEmpty(reportDate)||StringUtils.isEmpty(phone) ){
            return Result.error("请完善个人资料");
        }
        mealWorker.setReportName(reportName) ;
        mealWorker.setPhone(phone);
        if(!StringUtils.isEmpty(reportDate)){
            mealWorker.setReportDate(DateUtils.dateTime(DateUtils.YYYY_MM_DD,reportDate));
        }
        return Result.success(workerService.selectMealWorkerList(mealWorker));
    }

    @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
    @PostMapping("/insert")
    public Result insert(@RequestBody MealWorker mealWorker) {
        workerService.insertMealWorker(mealWorker);
        return Result.success("新增成功");
    }

    @PostMapping("/update")
    public Result update(@RequestBody MealWorker mealWorker) {
        workerService.updateMealWorker(mealWorker);
        return Result.success("修改");
    }


}
